<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <title>WebSocketTest</title>
</head>
<body>
<div id="message"></div>
<script type="text/javascript">
    window.onload = function () {
        //方法内容
        if ("WebSocket" in window) {
            console.log("您的浏览器支持 WebSocket!");
            // 打开一个 web socket
            var ws = new WebSocket("ws://192.168.19.54:8082/websocket/user001");
            ws.onopen = function () {
                // Web Socket 已连接上，使用 send() 方法发送数据
                ws.send({"sessionId":"112113"});

                console.log("数据发送中...");
            };
            ws.onmessage = function (evt) {
                var received_msg = evt.data;
                document.getElementById("message").append(received_msg + "/");
                console.log("数据已接收："+received_msg);
            };
            ws.onclose = function () {
                // 关闭 websocket
                console.log("连接已关闭...");
            };
        } else {
            // 浏览器不支持 WebSocket
            console.log("您的浏览器不支持 WebSocket!");
        }
    };
</script>
</body>
</html>